import 'package:cached_network_image/cached_network_image.dart';
import 'package:e_book/components/author_tile/my_author_tile_skeleton.dart';
import 'package:e_book/utils/header_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class MyAuthorTitle extends StatelessWidget {
  final List? authors;
  const MyAuthorTitle({super.key, this.authors});

  @override
  Widget build(BuildContext context) {
    if (authors == null) {
      // 骨架屏
      return const MyAuthorTileSkeleton();
    } else {
      return Column(
        children: List.generate(authors!.length, (index) {
          return Padding(
            padding: EdgeInsets.only(bottom: 15.h),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // 作者信息

                Row(
                  children: [
                    ClipOval(
                      child: CachedNetworkImage(
                        height: 40.r,
                        width: 40.r,
                        fit: BoxFit.cover,
                        httpHeaders: HeaderUtil.randomHeader(),
                        imageUrl: authors?[index].avatar ?? '',
                      ),
                    ),
                    10.horizontalSpace,
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          authors?[index].name ?? '',
                          style: TextStyle(
                            fontSize: 14.sp,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                        Text(
                          authors?[index].role ?? '',
                          style: TextStyle(
                            fontSize: 13.sp,
                            color: Theme.of(context).colorScheme.inversePrimary,
                          ),
                        ),
                      ],
                    ),
                  ],
                ),

                // 了解作者

                Row(
                  children: [
                    Text(
                      '了解作者',
                      style: TextStyle(
                        fontSize: 14.sp,
                        color: Theme.of(context).colorScheme.inversePrimary,
                      ),
                    ),
                    3.horizontalSpace,
                    Icon(
                      Icons.arrow_forward_ios,
                      size: 13.sp,
                      color: Theme.of(context).colorScheme.inversePrimary,
                      weight: 1,
                    ),
                  ],
                )
              ],
            ),
          );
        }),
      );
    }
  }
}
